﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Models;

namespace BLL
{
    public class PJSampleInManager
    {
        private PJSampleInService objPJSampleInService = new PJSampleInService();
        public string InsertIsNoSuccess(PJSampleIn main)
        {
            string result;
            string serialNum = GetLastSerialNum(main.OrderType, main.OrderPurpose, main.BusinessReason);
            if (!string.IsNullOrEmpty(serialNum))
            {
                int temp = int.Parse(serialNum.Substring(4,4));
                temp++;
                serialNum = "3" + main.SerialNum + temp.ToString().PadLeft(4, '0');
                main.SerialNum = serialNum;
            }
            else
            {
                main.SerialNum = "3" + main.SerialNum + "0001";
            }
            int a = IsNoSampleIn(main.WorkParentId);
            if(a==0)
            {
                InsertInfo(main);
                result = main.SerialNum;
            }
            else
            {
                result = "false";
            }
            return result;
        }
        public string GetLastSerialNum(string orderType, string orderPurpose, string businessReason)
        {
            return objPJSampleInService.GetLastSerialNum(orderType, orderPurpose, businessReason);
        }
        public int IsNoSampleIn(int workParentId)
        {
            return objPJSampleInService.IsNoSampleIn(workParentId);
        }
        private int InsertInfo(PJSampleIn main)
        {
            return objPJSampleInService.InsertInfo(main);
        }
        public PJSampleIn GetSampleIn(int workParentId)
        {
            return objPJSampleInService.GetSampleIn(workParentId);
        }
        public int UpdateInfo(PJSampleIn main)
        {
            return objPJSampleInService.UpdateInfo(main);
        }
        public int UpdateSapBill(string sapBill, int workParentId)
        {
            return objPJSampleInService.UpdateSapBill(sapBill, workParentId);
        }
        public int UpdateStatues(int workParentId)
        {
            return objPJSampleInService.UpdateStatues(workParentId);
        }
    }
}
